package rpc

import (
	"context"
	"errors"
	pb "forum/idl/pb/comment"
	"forum/pkg/e"
)

// CommentCreate 创建评论
func CommentCreate(ctx context.Context, req *pb.CommentRequest) (resp *pb.CommentCommonResponse, err error) {
	resp, err = CommentClient.CommentCreate(ctx, req)
	if err != nil {
		return
	}

	if resp.Code != e.SUCCESS {
		err = errors.New(resp.Msg)
		return
	}
	return
}

// CommentUpdate 更新评论
func CommentUpdate(ctx context.Context, req *pb.CommentRequest) (resp *pb.CommentCommonResponse, err error) {
	resp, err = CommentClient.CommentUpdate(ctx, req)
	if err != nil {
		return
	}

	if resp.Code != e.SUCCESS {
		err = errors.New(resp.Msg)
		return
	}
	return
}

// CommentDelete 删除评论
func CommentDelete(ctx context.Context, req *pb.CommentRequest) (resp *pb.CommentCommonResponse, err error) {
	resp, err = CommentClient.CommentDelete(ctx, req)
	if err != nil {
		return
	}

	if resp.Code != e.SUCCESS {
		err = errors.New(resp.Msg)
		return
	}
	return
}

// CommentList 获取帖子所有评论
func CommentList(ctx context.Context, req *pb.CommentRequest) (resp *pb.CommentDetailResponse, err error) {
	resp, err = CommentClient.CommentList(ctx, req)
	if err != nil {
		return
	}

	if resp.Code != e.SUCCESS {
		err = errors.New(e.GetMsg(int(resp.Code)))
		return
	}
	return
}

// CommentGet 获取用户所有评论
func CommentGet(ctx context.Context, req *pb.CommentRequest) (resp *pb.CommentDetailResponse, err error) {
	resp, err = CommentClient.CommentGet(ctx, req)
	if err != nil {
		return
	}

	if resp.Code != e.SUCCESS {
		err = errors.New(e.GetMsg(int(resp.Code)))
		return
	}
	return
}
